package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.utils.DateUtil;
import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class PersonalMessage extends BaseDomain{
    public static final int STATE_UNREAD=0;//未读
    public static final int STATE_READED=1;//已读


    private String content;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "MM-dd HH:mm",timezone ="GMT+8" )
    private Date createTime;

    private Integer state;

    private User sender;

    private User getter;

    public String getStateName(){
        if (state==STATE_UNREAD){
            return "未读";
        }else {
            return "已读";
        }
    }
    public String getJson(){
        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("content",content);
        map.put("state",state);
        map.put("createTime", DateUtil.formatDate(createTime));
        if(sender!=null){
            map.put("senderId",sender.getId());
        }
        if(getter!=null){
            map.put("getterId",getter.getId());
        }
        return JSONUtils.toJSONString(map);
    }
}